﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Hosting;
using Configuration.ServerApi.Param;
using Configuration.ServerApi.Service;
using System.Threading.Tasks;

namespace Configuration.ServerApi.Controllers
{
    /// <summary>
    /// 用户管理Controller
    /// </summary>
    [Authorize("AuthJwt")]
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IHostEnvironment HostEnvironment;
        private readonly IUserService UserService;

        #region 构造函数

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="hostEnvironment"></param>
        /// <param name="userService"></param>
        public UserController(IHostEnvironment hostEnvironment,
            IUserService userService)
        {
            HostEnvironment = hostEnvironment;
            UserService = userService;
        }

        #endregion

        #region 用户登录

        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [AllowAnonymous]
        [HttpGet]
        [Route("AuthLogin")]
        public async Task<IActionResult> AuthLogin([FromQuery] UpdateModel param)
        {
            return await UserService.AuthLogin(param);
        }

        #endregion

        #region 修改登录用户密码

        /// <summary>
        /// 修改登录用户密码
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("UpdateLoginUserPassword")]
        public async Task<IActionResult> UpdateLoginUserPassword(UpdateModel param)
        {
            return await UserService.UpdateLoginUserPassword(param);
        }

        #endregion

        #region 获取用户列表

        /// <summary>
        /// 获取用户列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("UserList")]
        public async Task<IActionResult> UserList(SearchModel param)
        {
            return await UserService.UserList(param);
        }

        #endregion

        #region 获取用户详情

        /// <summary>
        /// 获取用户详情
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("UserDetail")]
        public async Task<IActionResult> UserDetail(SearchModel param)
        {
            return await UserService.UserDetail(param);
        }

        #endregion

        #region 获取登录用户详情

        /// <summary>
        /// 获取登录用户详情
        /// </summary>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("LoginUserDetail")]
        public async Task<IActionResult> LoginUserDetail()
        {
            return await UserService.LoginUserDetail();
        }

        #endregion

        #region 提交用户信息

        /// <summary>
        /// 提交用户信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("SubmitUser")]
        public async Task<IActionResult> SubmitUser(UpdateModel param)
        {
            return await UserService.SubmitUser(param);
        }

        #endregion

        #region 批量启用或禁用用户

        /// <summary>
        /// 批量启用或禁用用户
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("UpdateUserStatus")]
        public async Task<IActionResult> UpdateUserStatus(UpdateModel param)
        {
            return await UserService.UpdateUserStatus(param);
        }

        #endregion

        #region 批量删除用户信息

        /// <summary>
        /// 批量删除用户信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("DelUser")]
        public async Task<IActionResult> DelUser(UpdateModel param)
        {
            return await UserService.DelUser(param);
        }

        #endregion

        #region 获取角色列表

        /// <summary>
        /// 获取角色列表
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("RoleList")]
        public async Task<IActionResult> RoleList(SearchModel param)
        {
            return await UserService.RoleList(param);
        }

        #endregion

        #region 获取角色详情

        /// <summary>
        /// 获取角色详情
        /// </summary>
        /// <param name="param">搜索条件</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("RoleDetail")]
        public async Task<IActionResult> RoleDetail(SearchModel param)
        {
            return await UserService.RoleDetail(param);
        }

        #endregion

        #region 提交角色信息

        /// <summary>
        /// 提交角色信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("SubmitRole")]
        public async Task<IActionResult> SubmitRole(UpdateModel param)
        {
            return await UserService.SubmitRole(param);
        }

        #endregion

        #region 批量启用或禁用角色

        /// <summary>
        /// 批量启用或禁用角色
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("UpdateRoleStatus")]
        public async Task<IActionResult> UpdateRoleStatus(UpdateModel param)
        {
            return await UserService.UpdateRoleStatus(param);
        }

        #endregion

        #region 批量删除角色信息

        /// <summary>
        /// 批量删除角色信息
        /// </summary>
        /// <param name="param">更新参数集</param>
        /// <returns>JSON结果集</returns>
        [HttpPost]
        [Route("DelRole")]
        public async Task<IActionResult> DelRole(UpdateModel param)
        {
            return await UserService.DelRole(param);
        }

        #endregion

    }
}
